<!-- 单选页面 -->

<template>
	<view class="container">
		<z-paging :auto="false" ref="paging" v-model="dataList" loading-more-no-more-text="暂无更多数据" @query="queryList" :loading-more-enabled="data.isPager">
			<view slot="top" v-show="showSelectItem" name='fade' style="padding: 1rem 0px 0px;"
				v-if="data.fuzzyList&&data.fuzzyList.length>0">
				<view class="v-row" v-for="(ite,i ) in data.fuzzyList" :key="i">
					<view class="t-title">{{ite.name}}</view>
					<view class="t-content">
						<input class="i-content" type="text" :placeholder="'请输入'+ite.name" v-model="ite.value" />
					</view>
				</view>
			</view>

			<view slot="top" class="commit_btn" style="margin-top: 20px;text-align: center;" v-if="data.fuzzyList.length>0">
				<button @click="select()" style="width: 50%;height: 1.6rem;" size="mini">{{showSelectItem?'搜索':'刷新'}}
				</button>
				<button @click="handlerSelectMore()" class="btn-select" size="mini">{{showSelectItem?'关闭':'检索'}}
				</button>
			</view>

			<view class="item" style="margin-left: 16rpx;padding-right: 1rem" v-for="(item,index) in dataList"
				:key="index" @click="checkItem(item)">
				<view>
					{{ item.name?item.name:'' }} * {{item.value?item.value:''}}
				</view>
				<!-- <text>{{item.otherInfo}}</text> -->
			</view>
		</z-paging>
	</view>
</template>

<script>
	import requestUtils from '@/common/utils/requestUtils.js'
	import commonConstants from '@/common/constants/commonConstants.js'

	//选择用户多选
	export default {
		data() {
			return {
				dataList: [],
				showSelectItem: true,
				data: {
					param: {},
					url: '',
					isPager: false,
					fuzzyList: [],
				},
			}
		},
		methods: {
			handlerSelectMore() {
				this.showSelectItem = !this.showSelectItem
			},
			select() {
				this.$refs.paging.reload();
			},
			checkItem(item) {
				// #ifdef APP-NVUE
				const eventChannel = this.$scope.eventChannel; // 兼容APP-NVUE
				// #endif
				// #ifndef APP-NVUE
				const eventChannel = this.getOpenerEventChannel();
				// #endif
				eventChannel.emit('getSelect', item);
				uni.navigateBack()
			},
			queryList(pageNo, pageSize) {
				console.log(JSON.stringify(this.data), "======");
				if (this.data.url) {
					let that = this
					if (this.data.fuzzyList && this.data.fuzzyList.length > 0) {
						this.data.fuzzyList.forEach(item => {
							this.data.param[item.key] = item.value
						})
					}
					console.log("触发页面刷新");
					if (this.data.isPager) {

						requestUtils.getListByPager(this.data.url, this.data.param, {
							page: pageNo,
							limit: pageSize * 3
						}, (result) => {
							console.log(result);
							if (result.data.rows) {
								let list = result.data.rows
								that.$refs.paging.complete(list);
							}
						}, (error) => {
							that.pagingError(error)
						})

					} else {
						requestUtils.getListByCondition(this.data.url, this.data.param, (result) => {
							let list = result.list
							this.$refs.paging.complete(result.list);
							// this.$refs.paging.complete(list);
						}, (error) => {
							that.pagingError(error)
						})
					}
				}
			},

			pagingError(error) {
				this.$refs.paging.complete(false);
				uni.showModal({
					content: error.msg,
					showCancel: false
				});
			}
		},
		onLoad(lodata) {
			console.log("onLoad---", JSON.stringify(lodata));
			if (lodata.ul) {
				this.data.url = lodata.ul;
			}

			this.data.isPager = lodata.ip == "true";

			if (lodata.pa) {
				this.data.param = JSON.parse(lodata.pa)
			}

			if (lodata.fz && lodata.fz != "undefined") {
				this.data.fuzzyList = JSON.parse(lodata.fz)
			}
			console.log("data-----", JSON.stringify(this.data));
		},
		mounted() {
			this.$nextTick(() => {
				this.queryList(0, 10)
			})
		},
		onHide() {
		}

	}
</script>

<style>
	@import url("@/pages/general/general.css");

	.t-content {
		flex: 1;
		margin-left: 10px;
	}

	.btn-select {
		width: 30%;
		height: 1.6rem;
		margin-left: 0.6rem;
		background-color: #fff;
		border: 1rpx solid #1E6AD3;
		color: #1E6AD3;
	}

	.btn-confirm {
		background: #1E6AD3;
		border-radius: 10rpx;
		color: #fff;
		margin: 10px auto;
		width: 70%;
	}

	.v-right {
		display: flex;
		align-items: center;
		padding: 5px 1rem 5px 0.5rem
	}
</style>